package cn.steam.aop;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhang jintao on 2022/09/24
 **/
@Component
@Aspect
public class NeedSignAspect {

    @Before("@annotation(needSign)")
    public void checkSign(NeedSign needSign) {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (requestAttributes == null) {
            return;
        }
        HttpServletRequest request = requestAttributes.getRequest();
        String sign = request.getHeader("Sign");
        System.out.println("签名切面拦截:" + sign);
    }

}
